// Copyright 2010 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


/**
 * @fileoverview Defines the Script class and supporting information.  The
 * Script class is POD (plain old data) and is intended to be completely
 * accessible; i.e. there is no data hiding or get/set functions.  However,
 * it is also up to the user of the class to ensure all the data is of the
 * correct type and has valid values.  The design intention was to use this
 * class purely as data storage and manage it through another object, in the
 * case of the shell extension that would be the ScriptSet class.  @see
 * shellExtension.ScriptSet for more details.
 *
 * An overview of the Script state, to be maintained by the user:
 *
 *   BAD_OBJECT: The state of the Script upon creation or at any point it
 *       contains an invalid id.
 *   FAILED: The id is valid but the data or type is invalid.
 *   INIT: If type is JS_URL or CSS_URL and data is null.
 *   LOADED: 1) If type is JS_URL or CSS_URL and data is not null. 2)  The
 *       type is JS_CODE or CSS_CODE.
 *
 * The Script class defines a "script" which can be either javascript or css
 * code and stores the code explicitly.  The way it works is the id will be
 * null if the script is defined as JS_CODE or CSS_CODE otherwise it will be
 * the location (url) from wheree the code will be retrieved.  Once the code
 * has been retrieved (or loaded immediately) it resides in data.  From then on
 * the script should be considered "cached" in memory until the script is
 * reset/reloaded.
 *
 * Public functions:
 *   shellExtension.Script() - Constructs a new Script object.  The initial
 *       state is BAD_OBJECT.
 *
 * Public prototype functions for shellExtension.Script:
 *   clone() - Returns a new Script object that has the same values as the
 *       owner of the function.
 *
 * @author jasonstredwick@google.com (Jason Stredwick)
 */


goog.provide('shellExtension.Script');

goog.require('shellExtension.manifest');
goog.require('shellExtension.status');



/**
 * The script class defines information about a either css or js script.
 * Everything within the class is public.  See the file overview for more
 * information about the Script class.
 * @constructor
 */
shellExtension.Script = function() {
  /**
   * The script data is stored here.
   * @type {?string}
   */
  this.data = null;

  /**
   * The id both represents the script as an identifier and how to retrieve its
   * information remotely.
   * @type {?string}
   */
  this.id = null;

  /**
   * This is the load status of the script.
   * @type {shellExtension.status.Value}
   */
  this.status = shellExtension.status.Value.BAD_OBJECT;

  /**
   * The type of script; language, url/inline.
   * @type {?shellExtension.manifest.script.Property}
   */
  this.type = null;
};


/**
 * Creates a clone of the script object who owns this function.
 * @return {!shellExtension.Script} A copy of the script.
 */
shellExtension.Script.prototype.clone = function() {
  var script = new shellExtension.Script();
  script.data = this.data;
  script.id = this.id;
  script.status = this.status;
  script.type = this.type;
  return script;
};

